package com.lancoo.znbkxx.ielts.base

import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.jaeger.library.StatusBarUtil
import com.lancoo.znbkxxtea.ielts.utils.KeyboardUtil
import kotlinx.android.synthetic.main.activity_main.*


/**
 * auther: 王国龙
 *  Date：
 * describe:
 */
abstract class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val contentView: View = layoutInflater.inflate(setLayout(), null)
        setContentView(contentView)

        KeyboardUtil(this, contentView)//适配布局上顶，必须得加

        initData()
        initView()
        StatusBarUtil.setTransparentForImageView(this, null)
        // 设置根布局的paddingTop
        RlTopbar.setPadding(0, getStatusBarHeight(this), 0, 0) //适配刘海屏
    }

//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//        setContentView(setLayout())
//        initData()
//        initView()
//        StatusBarUtil.setTransparentForImageView(this, null)
//        // 设置根布局的paddingTop
//        RlTopbar.setPadding(0, getStatusBarHeight(this), 0, 0) //适配刘海屏
//    }

    // 设置布局
    protected abstract fun setLayout(): Int

    // 初始化组件
    protected abstract fun initView()

    protected abstract fun initData()

    /**
     * 获取状态栏高度
     *
     * @param context
     * @return
     */
    open fun getStatusBarHeight(context: Context): Int {
        var statusBarHeight = 0
        val resourceId =
            context.resources.getIdentifier("status_bar_height", "dimen", "android")
        if (resourceId > 0) {
            statusBarHeight = context.resources.getDimensionPixelSize(resourceId)
        }
        return statusBarHeight
    }


    /*
    * android 全屏去掉底部虚拟导航栏的方法
    * */
    override fun onWindowFocusChanged(hasFocus: Boolean) {
        super.onWindowFocusChanged(hasFocus)
        if (hasFocus) {
            window.decorView.systemUiVisibility =
                (View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
        }
    }

}